package JavaFoundation;

import java.util.concurrent.atomic.AtomicInteger;

/*
CAS:比较并交换
    unsafe.compareAndSwapInt
    底层原理：自选锁+unsafe
 */
public class CASDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(5);
        System.out.println(atomicInteger.compareAndSet(5, 2019)+"===="+atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(5, 2017)+"==="+atomicInteger.get());
        atomicInteger.getAndIncrement();
    }
}
